#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n;
int cnt;
int row[maxn], color[maxn], diag[2 * maxn], backdiag[2 * maxn];
void backtrack(int i) {
  if (i == n) {
    if (cnt < 3) {
      for (int k = 0; k < n; ++k) cout << row[k] + 1 << ' ';
      cout << '\n';
    }
    cnt++;
    return;
  }
  // can I put it at j?
  for (int j = 0; j < n; ++j) {
    if (color[j] || diag[i + j] || backdiag[n + i - j]) continue;
    row[i] = j;
    color[j] = diag[i + j] = backdiag[n + i - j] = true;
    backtrack(i + 1);
    color[j] = diag[i + j] = backdiag[n + i - j] = false;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  backtrack(0);
  cout << cnt << '\n';
  return 0;
}
